import requests
from MxsShop.settings import yp_apikey


class YunPian:

    def __init__(self, api_key):
        self.api_key = api_key
        self.url = "https://sms.yunpian.com/v2/sms/single_send.json"

    def send_single_sms(self, code, mobile):
        # 发送单条短信
        params = {
            "apikey": self.api_key,
            "mobile": mobile,
            "text": f"【刘昌富测试】您的验证码是{code}"
        }
        response = requests.post(self.url, data=params)
        return response.json()


if __name__ == "__main__":
    yun_pina = YunPian(yp_apikey)
    yun_pina.send_single_sms('2041', '18620059772')
